LocIndexer error

by: spiff, 8 years ago


Am really struggling here, and there doesn't seem to be a straight forward answer to this, so posting it here.

I have an excel sheet with Column A (Ccys) which has a list of ccy pairs and Column B (SpotLevel) which has numbers
Below is what my code reads as:


###############################
base_ccy_list = ['EUR','USD']
local_ccy_list = ['JPY]

wb = pd.read_excel('data.xlsx', 'Spots', header=0, index_col='Ccys',
                       parse_cols='A:B')

spot_level = wb.loc[base_ccy_list[1] + local_ccy_list[0], 'SpotLevel']
#################################

This throws the error:
<pandas.core.indexing._LocIndexer at 0x88d68d0>

base_ccy_list[1]+local_ccy_list[0]=='USDINR'

gives True


Here I have asked on stackoverflow: http://stackoverflow.com/q/38560748/6577574

And the answers are very roundabout, and so I prefer my method.. but I am making some basic data structures error here which am not able to solve... Pls help!



You must be logged in to post. Please login or register an account.



Guess here is how I am getting around it:


wb['SpotLevel'].iloc[np.where(wb.index==base_ccy_list[0]+local_ccy_list[0])[0]]


:)

EDIT - this doesn't work either.. throws TypeError: list indices must be integers, not list

apols for the spam, not sure how to delete the post!

-spiff 8 years ago
Last edited 8 years ago

You must be logged in to post. Please login or register an account.


The error: TypeError: list indices must be integers, not list

Means you're attempting to reference an index, which must be an integer, but you're passing a list.

Are you familiar with what an index is? In this case, all of those [0] are valid inputs for an index, but all of them are also inputting into either iloc (an index), or in the wb.index...thus, one of those indexes is returning a list and isn't a valid index.

Try printing out  base_ccy_list[0], local_ccy_list[0], and np.where(wb.index==base_ccy_list[0]+local_ccy_list[0])[0]

See the output of all of those, one of those is probably a list. You may need to do something like base_ccy_list[0][0]...etc, depending on what the data actually looks like.

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.